package com.demo.nio;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.net.Socket;
import java.net.UnknownHostException;

/**   
* @Description: TODO(用一句话描述该文件做什么) 
* @author thomas_liu  
* @date 2018年6月2日 下午9:40:09 
* @version V1.0   
*/
public class Client {

	public static void main(String[] args) throws UnknownHostException, IOException {
		//要连接的服务端IP地址
		String host = "127.0.0.1";
		//要连接的服务端对应的监听端口
		int port = 8899;
		//与服务端建立连接
		Socket client = new Socket(host, port);
		
		//建立连接后就往服务端写数据
		Writer writer = new OutputStreamWriter(client.getOutputStream());
		writer.write("Hello Server.");
		writer.flush();//写完后要记得flush，清空缓冲区
		
		//写完以后进行读操作
		Reader reader = new InputStreamReader(client.getInputStream());
		char chars[] = new char[64];
		
		writer.close();
		client.close();
	}
	
	
}
